
jsool.onReady(function inicializa(){
	//atalhos
	var EM = js.core.EventManager,		
		EX = js.core.Exception,
		EL = js.dom.Element;
	
	//prepara menu principal
	function inicializaRibbon(){
		var barItems = Raze.query(".menu-item"),
			ribbonItems = Raze.query(".ribbon-container"),
			ribbons = {},ultimo,
			visivel,
			el,
			i=0,
			ribbonName;
		
		while(el=ribbonItems[i++]){
			ribbonName = el.getAttribute("ribbon").trim();
			ribbons[ribbonName] = el;
			
			if(!el.className.match(/\bdefault\b/)){
				el.style.display = "none";
			}else{
				visivel = el;
			}
		}
		
		i=0;
		
		while(el=barItems[i++]){
			EM.on(el,"click",function(){
				var name = this.getAttribute("ribbon");
				if(visivel)visivel.style.display = "none";
				
				if(ultimo)jsool.get(ultimo).removeClass("active");
				
				jsool.get(this).addClass("active");
				
				visivel = ribbons[name];
				
				if(visivel)visivel.style.display = "block";
				
				ultimo = this; 
			});
		}
		
		var hash = window.location.pathname.match(/[/]requisiteworks[/](\w+)([/].*)?/);
		if(hash){
			hash = hash[1];
			if(ribbons[hash]){
				if(visivel)visivel.style.display = "none";
				visivel = ribbons[hash];
				if(visivel)visivel.style.display = "block";
			}
			
			ultimo = Raze.queryNode("li[ribbon="+hash+"]");
			if(ultimo)jsool.get(ultimo).addClass("active");
		}
	}
	
	inicializaRibbon();
});